//
//  WWGuideController.m
//  新特性测试
//
//  Created by 张湾湾 on 16/7/10.
//  Copyright © 2016年 张湾湾. All rights reserved.
//

#import "WWGuideController.h"

#import "UIView+WWExtension.h"
#import "WWGuideCell.h"

@interface WWGuideController ()

/**存放所有背景图片*/
@property (nonatomic,strong)NSArray<UIImage*>* imgArr;
@end

static NSString * const reuseIdentifier = @"Cell";

@implementation WWGuideController

#pragma mark - 重写init方法,指定布局
- (instancetype)init {
    
    // MARK: - 1.创建流水布局对象
    UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
    
    // 1.2 设置cell的大小
    // self.collectionView还没有值,nil
    // flowLayout.itemSize = self.collectionView.bounds.size;
    flowLayout.itemSize = [UIScreen mainScreen].bounds.size;
    
    // 1.3 水平方向滚动
    flowLayout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    // 1.4 调整item间距
    flowLayout.minimumLineSpacing = 0;
    
    
    return [super initWithCollectionViewLayout:flowLayout];
}


- (void)viewDidLoad {
    [super viewDidLoad];
        // MARK: - 1.设置基本属性
        self.collectionView.backgroundColor = [UIColor redColor];
        
        // 1.关闭弹簧效果
        self.collectionView.bounces = NO;
        
        // 2.设置分页效果
        self.collectionView.pagingEnabled = YES;
        
        // 3.关闭底部的滚动条
        self.collectionView.showsHorizontalScrollIndicator = NO;
        
        // 注册cell
        [self.collectionView registerClass:[WWGuideCell class] forCellWithReuseIdentifier:reuseIdentifier];
    
    }

#pragma mark
#pragma mark - 代理方法
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
    
    return 1;
}


- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    
    return self.imgArr.count;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    
    WWGuideCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:reuseIdentifier forIndexPath:indexPath];
    
    // 设置背景图片
    cell.backgroundView = [[UIImageView alloc] initWithImage:self.imgArr[indexPath.item]];
    if(self.guideControllerBlock)
    {
        cell.didClickButtonBlock = self.guideControllerBlock;
    }
    // 最后一个cell现实按钮,其他的隐藏!
    if (indexPath.item == self.imgArr.count - 1) {
        cell.experienceBtn.hidden = NO;
    } else {
        
        cell.experienceBtn.hidden = YES;
    }
    
    return cell;
}

#pragma mark
#pragma mark - 懒加载
- (NSArray<UIImage *> *)imgArr{
    if (!_imgArr) {
        _imgArr = @[
                    [UIImage imageNamed:@"img1"],
                    [UIImage imageNamed:@"img2"],
                    [UIImage imageNamed:@"img3"],
                    
                    ];
    }
    return _imgArr;
}



 @end
